package com.jack.leetcode.eachproblem_2020;

/**
 * Created by zhang_j on 2020/10/28
 */
public class 比特位计数 {

    public static void main(String[] args) {
        countBits(3);
    }

    public static int[] countBits(int num) {
        int[] result = new int[num + 1];
        int i = 0,b = 1;
        while(b <= num){
            while(i < num && i + b <= num){
                result[i + b] = result[i] + 1;
                ++i;
            }
            i = 0;
            b <<= 1;
        }
        return result;
    }
}
